<!--
/**
* Author: txj
* Date:2023年10月19日17:24:45 
* Desc: 添加会员卡
*/
-->
<template>
  <view class="main">
    <view class="fc8 fs28">添加影城会员卡，可在本系统内选择会员特惠价进行购票，如绑卡异常，可联系影城进行处理。</view>
    <view class="chooseCinema mtb40 ba" :class="cinemaInfo && cinemaInfo.cinemaName ? 'fc3' : 'chooseCinema-text'" @click="chooseCinema" v-if="hasCinema">{{ cinameName }}</view>
    <view class="mtb40 ba">
      <u-input placeholder="请输入会员卡卡号" v-model="cardCode" type="text" clearable />
    </view>
    <view class="mtb40 ba">
      <u-input placeholder="请输入会员卡密码" v-model="cardPassword" type="text" clearable />
    </view>
    <yy-button @click="bindCard">绑定会员卡</yy-button>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        cardCinema: '',
        cardCode: '',
        cardPassword: '',
        cinemaInfo: {}
      }
    },
    onLoad(options) {
      this.query = options || {}
      this.orderId = this.query.cardId || ''
      uni.removeStorageSync('selectCinema')
      if (!this.$auth.getSingleModel()) {
        this.cinemaInfo = {
          cinemaId: this.$auth.getLocBaseSet().cinemaId,
          cinemaName: this.$auth.getLocBaseSet().cinemaName
        }
      }
      console.log('onLoad', this.cinemaInfo)
    },
    onShow() {
      if (this.$auth.getSingleModel()) {
        this.cinemaInfo = uni.getStorageSync('selectCinema') || {}
      }
      console.log('this.cinemaInfo onShow', this.cinemaInfo)
    },
    // 计算属性
    computed: {
      hasCinema() {
        return true
      },
      cinameName() {
        console.log('cinameName', this.cinemaInfo)
        if (this.cinemaInfo && this.cinemaInfo.cinemaName) {
          return this.cinemaInfo.cinemaName
        }
        return '请选择发卡影城'
      }
    },

    // 挂载完成
    mounted() {},

    // 创建完成
    created() {},

    // 挂载方法
    methods: {
      bindCard() {
        const query = {
          cardCode: this.cardCode,
          cardPassword: this.cardPassword,
          cinemaId: this.cinemaInfo ? this.cinemaInfo.cinemaId : ''
        }
        uni.$api.memberCard.bindCard(query).then((res) => {
          uni.setStorageSync('reCard', '绑定成功')
          this.$tools.navigateTo(-1)
        })
      },
      chooseCinema() {
        if (this.$auth.getSingleModel()) {
          this.$tools.navigateTo('/subPages/selectFilm/selectFilmByCard')
        }
      }
    }
  }
</script>
<style lang="scss" scoped>
  .main {
    padding: 40rpx;
    .chooseCinema {
      padding: 18rpx 18rpx;
    }
    .chooseCinema-text {
      color: rgb(192, 196, 204);
      font-size: 31rpx;
    }
  }
</style>
